package util

import (
	"sort"
	"strings"
)

const split = ","

//ToNoRepeatString remove duplicate data and convert result to string
func ToNoRepeatString(data ...string) string {
	if len(data) == 0 {
		return ""
	}

	tempMap := make(map[string]struct{})
	for i := range data {
		tempMap[data[i]] = struct{}{}
	}

	//sort data
	stringSlice := sort.StringSlice{}
	for tempData := range tempMap {
		stringSlice = append(stringSlice, tempData)
	}
	stringSlice.Sort()

	return strings.Join(stringSlice, split)
}
